package com.sky.controller.admin;


import com.aliyuncs.exceptions.ClientException;
import com.sky.result.Result;
import com.sky.utils.AliOssUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/admin/common/upload")
public class FileController {


    @PostMapping
    public Result<String> upFile(MultipartFile file) throws IOException, ClientException {
        String originalFilename = file.getOriginalFilename();
        byte[] fileBytes = file.getBytes();
        AliOssUtil aliOssUtil = new AliOssUtil("oss-cn-beijing.aliyuncs.com", "LTAI5tQSyjx2PwE3QvDQSPWL", "oCtG1hjhEn8x5qUlqNv2HZScHfDHvQ", "web-xty");
        String upload = aliOssUtil.upload(fileBytes, originalFilename);
        return Result.success(upload);
    }
}
